﻿<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    <style>
        html, body {
            height:100%;
        }

        .systitle{
            width:200px;
            float:left;
        }
        .users{
            display:none;
        }
    </style>
</head>

<body>
    <div class="navbar">
        <div class="systitle">
            <a href="/">
                <div class="logo"></div>
                <span class="title">企业网盘</span>
            </a>
        </div>        
        <div class="userinfo">            
            <div class="dropdown">
                <a id="dLabel" href="javascript:;" class="dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <i class="fa fa-user"></i>
                    <span class="username">admin</span>
                </a>
                <ul class="dropdown-menu" aria-labelledby="dLabel">
                   <li><a href="#" class="changepw"  data-toggle="modal" data-target="#changePWModal">修改密码</a></li>
                   <li class="users"><a href="#">用户管理</a></li>
                   <li><a href="#" class="logout">退出登录</a></li>
                </ul>
            </div>
        </div>
    </div>    
    @RenderBody()
    <div class="modal fade" id="changePWModal" tabindex="-1" role="dialog" aria-labelledby="changePWModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="changePWModalLabel">修改密码</h4>
                </div>
                <div class="modal-body">
                    <form id="changePWModalForm">
                        <div class="row form-group">
                            <div class="col col-sm-3 text-right">
                                <label class="label-margin-top input-notempty">旧密码</label>
                            </div>
                            <div class="col col-sm-8">
                                <input type="password" class="form-control" name="oldpw" placeholder="请输入旧密码">
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col col-sm-3 text-right">
                                <label class="label-margin-top input-notempty">新密码</label>
                            </div>
                            <div class="col col-sm-8">
                                <input type="password" class="form-control" name="pw" placeholder="请输入新密码">
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col col-sm-3 text-right">
                                <label class="label-margin-top input-notempty">确认密码</label>
                            </div>
                            <div class="col col-sm-8">
                                <input type="password" class="form-control" name="repw" placeholder="请再次输入新密码">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" id="btnSavePW" data-loading-text="提交中..." autocomplete="off" class="btn btn-primary">确定</button>
                </div>
            </div>
        </div>
    </div>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/icheck")
    @Scripts.Render("~/bundles/fileupload")
    @RenderSection("scripts", required: false)
</body>
<script type="text/javascript">
    $(function () {
        var u = _utility.userInfo();
        $(".logout").click(function(){
            $.cookie("token", '', { path: '/' });
            window.location.href = "/login";
        });
        $(".users").click(function () {
            window.location.href = "/usermanage";
        });
        if (u.Role == 'Admin') {
            $(".users").show();
        }
        $(".username").text(u.LoginName);
        $('#changePWModal').on('show.bs.modal', function (event) {
            var form = $("#changePWModalForm");
            form.find("[name='oldpw']").val('');
            form.find("[name='pw']").val('');
            form.find("[name='repw']").val('');
        });
        $("#btnSavePW").click(function () {
            var form = $("#changePWModalForm");
            var oldpw = $.trim(form.find("[name='oldpw']").val());
            var pw = $.trim(form.find("[name='pw']").val());
            var repw = $.trim(form.find("[name='repw']").val());
            if (oldpw == '') {
                toastr.warning("请输入旧密码");
                return;
            }
            if (pw == '') {
                toastr.warning("请输入新密码");
                return;
            }
            if (repw != pw) {
                toastr.warning("两次输入密码不一致");
                return;
            }
            $("#btnSavePW").button("loading");
            _utility.ajax({
                url: '/api/account/changepw?oldpw=' + oldpw + "&pw=" + pw,
                type: 'get',
                success: function (res) {
                    $("#btnSavePW").button("reset");
                    if (res.errcode == 0) {
                        toastr.info(res.errmsg);
                        $('#changePWModal').modal("hide");
                    } else {
                        toastr.warning(res.errmsg);
                    }
                }
            });
        });
    });
</script>
</html>
